package train.DAY623;

import java.util.*;

public class HomeWork623 {
    public static void main(String[] args) {
        Student student1 = new Student("李", 12, 90.0, 177.0);
        Student student2 = new Student("王", 11, 60.0, 165.0);
        Student student3 = new Student("刘", 15, 70.0, 180.0);
        Student student4 = new Student("关", 18, 80.0, 166.0);
        Student student5 = new Student("张", 10, 20.0, 190.0);
        //方式一在对象类继承comparable重写comparto
//        TreeSet<Student> treeSet = new TreeSet<>();
//        treeSet.add(student1);
//        treeSet.add(student2);
//        treeSet.add(student3);
//        treeSet.add(student4);
//        treeSet.add(student5);
      //  System.out.println(treeSet);

        //方式二内部类重写comparator
        TreeSet<Student> treeSet1 = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getId() - o2.getId();
            }
        });
        treeSet1.add(student1);
        treeSet1.add(student2);
        treeSet1.add(student3);
       // System.out.println(treeSet1);

        //方式三 Arrays.sort
        Student[] students={student1,student2,student4,student5};
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getId()-o2.getId();
            }
        });

        for (Student student : students) {
            System.out.println(student);
        }

    }




    public static void main1(String[] args) {
        String s="岩空落雪松惊梦 院静凝云水咽歌 衫碧吐花余点乱 纤纤捧碗玉颜酡";
        String[] s1 = s.split(" ");
        Stack stack = new Stack();
        for (int i = s1.length-1; i >=0; i--) {
            for (int j = 0; j < s1[i].length(); j++) {
                stack.push(s1[i].charAt(j));
            }
            for (int j = 0; j < s1[i].length(); j++) {
                System.out.print(stack.pull());
            }
            System.out.println();
        }
    }
}

class Stack{
   List<Object> list= new ArrayList<Object>();
   int index=0;
     public void push(Object a){
         list.add(index,a);
         index++;
     }

     public Object pull(){
         index--;

         return  list.get(index);

     }
}